/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Compras;

import Controlador.Bean.Compras.ProductoxOrden;
import Controlador.Bean.Compras.Solicitud;
import gui.General.Main;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author LiziTa
 */
public class BuscarSolicitud extends javax.swing.JInternalFrame {
public String ps;
  TableModel tb;
    /**
     * Creates new form BuscarSolicitud
     */
  
      private static BuscarSolicitud myoc=null;
     public static BuscarSolicitud getInstance(String ps) {
                 
          if(myoc == null){
                       myoc = new BuscarSolicitud(ps);    
            Main.getDesktop().add(myoc); 
            myoc.setVisible(true);
               myoc.toFront();           
                    }
                    else{
                        if (myoc.isClosed()|| !myoc.isVisible()) {
                                myoc = new BuscarSolicitud(ps); 
                                Main.getDesktop().add(myoc);
                                myoc.toFront();
                                myoc.setVisible(true);
                        }
                        else
                            myoc.toFront();
                    }
        
        
        
                return myoc;
    }
  
    public BuscarSolicitud(String ps) {
        
        
        
        
        this.ps=ps;
        initComponents();
         initComp();
//          TableRowSorter<TableModel> sorter  = new TableRowSorter<TableModel>((TableModel) jTable1.getModel());
//        jTable1.setRowSorter(sorter);
    }

    BuscarSolicitud() {
     
    }

    private void initComp() {
        tb = new TableModel();
        jTable1.setModel(tb);
    }
     class TableModel extends AbstractTableModel{
              
        //Two arrays used for the table data
        String[] columnNames = {"Producto", "Precio", "Cantidad"
                        , "Unidades"};
               
        List<ProductoxOrden> data = Controlador.Service.Compras.GestionCompra.obtenerProdxOrden2(ps);
       // List<Producto> productos = Controlador.Service.Almacen.GestionAlmacenes.obtenerProductos();
       
        @Override
        public int getRowCount()
        {
            return data.size();
        }
        
        @Override
        public int getColumnCount()            
        {
            return columnNames.length;
        }
        
        @Override
        public Object getValueAt(int row, int column)
        {        
           
            
            switch(column){
               
                case 0: return data.get(row).getIdOrdenCompra();
                case 1: return data.get(row).getPrecioUnitario();
                case 2 :return data.get(row).getCantidad();
               default:return data.get(row).getIdProducto();
                
           
        }
             }
        
        //Used by the JTable object to set the column names
        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
        
        //Used by the JTable object to render different
        //functionality based on the data type
        @Override
        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }
        
        @Override
        public boolean isCellEditable(int row, int column)
        {
           if (column == 0 || column == 1)
	   {
	        return false;
	   }
	   else
	   {
		return true;
	   }
        }
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setResizable(true);
        setTitle("Detalle ");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
